package com.sgb.goods.widget.pop;

import android.content.Context;

import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.entity.DictEntity;
import com.sgb.goods.utils.base.adapter.RecordPointCommonAdapter;
import com.swgk.core.dialog.PopViewHolder;

import java.util.Arrays;
import java.util.List;

/**
 * 公用的选择样式弹窗
 * 样式1：
 * 颜色：EF4033 （红色）
 * <p>
 *      itme内容1      √
 *      itme内容2
 *      itme内容3
 * </>
 * 注意：请勿修改此类任何代码，可继承扩展来实现自身需求
 *
 * @author cyj
 */
public class GoodsItemSelect1PopWindow extends GoodsPopWindow {

    public RecordPointCommonAdapter<DictEntity> adapter;

    public GoodsItemSelect1PopWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        // 列表适配器初始化
        adapter = new RecordPointCommonAdapter<DictEntity>(R.layout.goods_item_select_style_1, BR.viewModel) {
            @Override
            public boolean equivalentToObject(DictEntity object1, DictEntity object2) {
                if(null == object1 || null == object2) {
                    return false;
                }
                return null != object1.id && object1.id.equals(object2.id);
            }
        };
        return R.layout.goods_pop_item_select_1;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        holder.setBinding(BR.spw, this);

        // 关闭
        holder.getPop().findViewById(R.id.ll_boot).setOnClickListener(view -> {
            dissMiss();
        });

        // 确认
        adapter.setItemClickListener((adapter2, view, position) -> {
            if (onResultClick != null) {
                onResultClick.result(adapter.getData().get(position), position, null);
            }
            adapter.setRecordPoint();
            dissMiss();
        });
    }

    /**
     * 设置一个集合数据
     * @param list    List
     */
    public void setData(List<DictEntity> list) {
        // 设置选中默认项为第一项
        adapter.setDefaultItem(true);
        adapter.setNewData(list);
        adapter.setRecordPoint(adapter.oldObj);
    }

    /**
     * 设置一个数组数据
     * @param array    array
     */
    public void setData(DictEntity... array) {
        setData(Arrays.asList(array));
    }
}
